﻿@model ShoppingCartModel
@using Nop.Core
@using Nop.Core.Infrastructure
@using Nop.Web.Models.ShoppingCart;
@{
    var webHelper = EngineContext.Current.Resolve<IWebHelper>();
}
<div class="order-summary-content">
    @Html.Widget("order_summary_content_before")
    @Html.Partial("_OrderReviewData", Model.OrderReviewData)
    @if (Model.Items.Count > 0)
    {
        if (Model.Warnings.Count > 0)
        {
        <div class="message-error">
            <ul>
                @for (int i = 0; i < Model.Warnings.Count; i++)
                {
                    <li>@Model.Warnings[i]</li>
                }
            </ul>
        </div>
        }
@*we add enctype = "multipart/form-data" because "File upload" attribute control type requries it*@
        using (Html.BeginRouteForm("ShoppingCart", FormMethod.Post, new { enctype = "multipart/form-data" }))
        {
        <table class="cart">
            <colgroup>
                @if (Model.IsEditable)
                {
                    <col width="1" />
                }
                @if (Model.ShowSku)
                {
                    <col width="1" />
                }
                @if (Model.ShowProductImages)
                {
                    <col width="1" />
                }
                <col />
                <col width="1" />
                <col width="1" />
                <col width="1" />
            </colgroup>
            <thead>
                <tr class="cart-header-row">
                    @if (Model.IsEditable)
                    {
                        <th>
                            @T("ShoppingCart.Remove")
                        </th>
                    }
                    @if (Model.ShowSku)
                    {
                        <th>
                            @T("ShoppingCart.SKU")
                        </th>
                    }
                    @if (Model.ShowProductImages)
                    {
                        <th class="picture"></th>
                    }
                    <th>
                        @T("ShoppingCart.Product(s)")
                    </th>
                    <th>
                        @T("ShoppingCart.UnitPrice")
                    </th>
                    <th>
                        @T("ShoppingCart.Quantity")
                    </th>
                    <th class="end">
                        @T("ShoppingCart.ItemTotal")
                    </th>
                </tr>
            </thead>
            <tbody>
                @foreach (var item in Model.Items)
                {
                    <tr class="cart-item-row">
                        @if (Model.IsEditable)
                        {
                            <td class="remove-from-cart">
                                <input type="checkbox" name="removefromcart" value="@(item.Id)" />
                            </td>
                        }
                        @if (Model.ShowSku)
                        {
                            <td class="sku nobr">
                                @item.Sku
                            </td>
                        }
                        @if (Model.ShowProductImages)
                        {
                            <td class="product-picture">
                                <img alt="@item.Picture.AlternateText" src="@item.Picture.ImageUrl" title="@item.Picture.Title" />
                            </td>
                        }
                        <td class="product">
                            <a href="@Url.RouteUrl("Product", new { SeName = item.ProductSeName })" class="product-name">@item.ProductName</a>
                            @if (!String.IsNullOrEmpty(item.AttributeInfo))
                            {
                                <div class="attributes">
                                    @Html.Raw(item.AttributeInfo)
                                </div>
                            }
                            @if (!String.IsNullOrEmpty(item.RecurringInfo))
                            {
                                <div class="recurring-info">
                                    @Html.Raw(item.RecurringInfo)
                                </div>
                            }
                            @if (Model.IsEditable && item.AllowItemEditing)
                            {
                                var editCartItemUrl = Url.RouteUrl("Product", new {SeName = item.ProductSeName});
                                editCartItemUrl = webHelper.ModifyQueryString(editCartItemUrl, "updatecartitemid=" + item.Id, null);
                                <div class="edit-item">
                                    <a href="@editCartItemUrl">@T("Common.Edit")</a>
                                </div>
                            }
                            @if (item.Warnings.Count > 0)
                            {
                                <div class="message-error">
                                    <ul>
                                        @for (int i = 0; i < item.Warnings.Count; i++)
                                        {
                                            <li>@item.Warnings[i]</li>
                                        }
                                    </ul>
                                </div>
                            }
                        </td>
                        <td class="unit-price nobr">
                            <span class="product-unit-price">@item.UnitPrice</span>
                        </td>
                        <td class="qty nobr">
                            @if (Model.IsEditable)
                            {
                                if (item.AllowedQuantities.Count > 0)
                                {
                                <select name="itemquantity@(item.Id)" class="qty-dropdown">
                                    @foreach (var qty in item.AllowedQuantities)
                                    {
                                        <option selected="@qty.Selected" value="@qty.Value">@qty.Value</option>
                                    }
                                </select>
                                }
                                else
                                {
                                <input name="itemquantity@(item.Id)" type="text" value="@(item.Quantity)" class="qty-input" />
                                }

                            }
                            else
                            {
                                <span>@item.Quantity</span>
                            }
                        </td>
                        <td class="subtotal nobr end">
                            <span class="product-subtotal">@item.SubTotal</span>
                            @if (!String.IsNullOrEmpty(item.Discount))
                            {
                                <div class="discount">
                                    @T("ShoppingCart.ItemYouSave"): @item.Discount
                                </div>
                            }
                        </td>
                    </tr>
                }
            </tbody>
        </table>
                if (!String.IsNullOrEmpty(Model.CheckoutAttributeInfo))
                {
        <div class="selected-checkout-attributes">
            @Html.Raw(Model.CheckoutAttributeInfo)
        </div>
                }
        <div class="buttons">
            @if (Model.IsEditable)
            {
                <div class="common-buttons">
                    <input type="submit" name="updatecart" value="@T("ShoppingCart.UpdateCart")" class="button-2 update-cart-button" />
                    <input type="submit" name="continueshopping" value="@T("ShoppingCart.ContinueShopping")" class="button-2 continue-shopping-button" />
                </div>
                @Html.Partial("_CheckoutAttributes", Model.CheckoutAttributes, new ViewDataDictionary())
            }
        </div>
        <div class="cart-footer">
            @Html.Widget("order_summary_cart_footer")
            @if (Model.IsEditable)
            {
                if (!String.IsNullOrEmpty(Model.MinOrderSubtotalWarning))
                {
                <div>
                    <div class="min-amount-warning">
                        @Model.MinOrderSubtotalWarning
                    </div>
                </div>
                }
            }
            <div class="cart-collaterals">
                @if (Model.IsEditable)
                {
                    <div class="deals">
                        @Html.Partial("_DiscountBox", Model.DiscountBox)
                        @Html.Partial("_GiftCardBox", Model.GiftCardBox)
                        @Html.Widget("order_summary_content_deals")
                    </div>
                    @Html.Partial("EstimateShipping", Model.EstimateShipping)
                }
            </div>
            <div class="totals">
                @Html.Action("OrderTotals", "ShoppingCart", new { isEditable = Model.IsEditable })
                @if (Model.IsEditable)
                {
                    if (Model.TermsOfServiceOnShoppingCartPage)
                    {
                        <div id="terms-of-service-warning-box" title="@T("Checkout.TermsOfService")" style="display:none;">
                            <p>@T("Checkout.TermsOfService.PleaseAccept")</p>
                        </div>
                        <div class="terms-of-service">
                            <input id="termsofservice" type="checkbox" name="termsofservice" />
                            @T("Checkout.TermsOfService.IAccept")
                            <span class="read" onclick="javascript:OpenWindow('@Url.RouteUrl("TopicPopup", new { SystemName = "conditionsofUse" })', 450, 500, true)">@T("Checkout.TermsOfService.Read")</span>
                        </div>
                    }
                    <div class="checkout-buttons">
                        @if (String.IsNullOrEmpty(Model.MinOrderSubtotalWarning))
                        {
                            <script type="text/javascript">
                                $(document).ready(function () {
                                    $('#checkout').click(function () {
                                        //terms of service
                                        var termOfServiceOk = true;
                                        if ($('#termsofservice').length > 0) {
                                            //terms of service element exists
                                            if (!$('#termsofservice').is(':checked')) {
                                                $("#terms-of-service-warning-box").dialog();
                                                termOfServiceOk = false;
                                            } else {
                                                termOfServiceOk = true;
                                            }
                                        }
                                        return termOfServiceOk;
                                    });
                                });
                            </script>
                            <button type="submit" id="checkout" name="checkout" value="checkout" class="button-1 checkout-button">
                                <span>@T("Checkout.Button")</span>
                            </button>
                        }
                    </div>
                    <div class="addon-buttons">
                        @*Payment method buttons (e.g. GoogleCheckoutButton, Paypal Express)*@
                        @Html.Partial("_ButtonPaymentMethod", Model)
                    </div>
                }
            </div>
        </div>
        if (Model.IsEditable)
        {
             @Html.Action("CrossSellProducts", "Catalog")
        }
        }
    }
    else
    {
        @T("ShoppingCart.CartIsEmpty")
    }
    @Html.Widget("order_summary_content_after")
</div>
